<template>
  <div class="zss_guanlibox">
    <zss-headermenu></zss-headermenu>
    
    <div style="margin-bottom:10px">
      <p class="zss_p">积分管理</p>
      <Input v-model="value4" icon="ios-search" placeholder="请输入学生信息" style="width: 200px"></Input>
      <Button type="primary" @click="sousuo" style="padding:4px 15px">搜索</Button>
      <Button type="success" @click="daochu" style="padding:4px 15px;float:right;margin-right:10px">导出</Button>
    </div>
    <!-- 加载进度圈开始 -->
    <Spin size="large" fix v-if="spinShow"></Spin>
    <!-- 加载进度圈结束 -->
    <Table border ref="selection" :row-class-name="rowClassName" :columns="columns4" :data="xsxinxi" @on-row-click="zssshow"></Table>

    <!-- 分页开始 -->
    <Page :total="xsfy.totalResult" :show-total="true" :page-size="xsfy.showCount" @on-change="changePage" show-elevator class-name="zss_page"></Page>
    <!-- 分页结束 -->



    <Modal v-model="modalalert" title="积分查看">
      <div style="overflow:hidden">
        <Card dis-hover style="width:100%">
          <div style="text-align:center" class="zss_glxq">
            <Row>
              <Col span="8">
                <h3>{{surplus}}</h3>
              </Col>
              <Col span="16">
                <p>姓名：{{userName}}</p>
                <p>学号：{{userCode}}</p>
                <p>学院：{{college_name}}</p>
                <p>班级：{{className}}</p>
              </Col>
            </Row>
          </div>
        </Card>
      </div>

      <div style="margin-top:10px;overflow:auto;max-height:300px">
        <Card dis-hover style="width:100%" :padding="0" :bordered="false">
          <div style="text-align:center;">
            <Table border :columns="columnsopen" :data="dataopen" text-align='center'></Table>
          </div>
        </Card>
      </div>
            
      <div style="text-align:center;margin-top:10px;overflow:hidden">
        <Button type="info" @click="zssczfs = true">重置分数</Button>
        <Button type="error" @click="zssfskc = true">分数扣除</Button>
        <Button type="success" @click="zssfssz = true">分数设置</Button>
        <Button type="warning" @click="zssbz = true">备注填写</Button>
        <Button type="primary" @click="daochujl">记录导出</Button>
      </div>
      
    </Modal>

    <Modal v-model="zssczfs">
      <p slot="header" style="color:#f60;text-align:center">
          <Icon type="information-circled"></Icon>
          <span>重置分数</span>
      </p>
      <div style="text-align:center">
          您确定要重置分数吗？
      </div>
      <div slot="footer">
          <Button type="error" size="large" long :loading="modal_loading" @click="zssczfj">确定重置</Button>
      </div>
    </Modal>
    <Modal v-model="zssfskc" title="扣分规则">        
      <p style="margin-bottom:10px">
        选择扣分规则：
        <Select style="width:200px" @on-change="kfxxchange">
          <Option v-for="(item, index) in kfxx" :value="index" :key="item.value">{{item.content}}</Option>
        </Select>
      </p>
      <p>
        扣除分数：
        <span>{{kf.fs}}</span>
      </p>
      <div slot="footer">
        <Button type="primary" size="large" @click="gzqd">确定</Button>
      </div>     
    </Modal>
    <Modal v-model="zssfssz" title="设置分数">
      <p style="text-align:center">
        设置分数：
        <Input v-model="valueinput" autofocus style="width: 60px"></Input>
      </p> 
      <div slot="footer">
        <Button type="primary" size="large" @click="szfs">确定</Button>
      </div>  
    </Modal>
    <Modal v-model="zssbz" title="备注">
      <p>
        填写备注：
        <Input v-model="beizhu" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入..."></Input>
      </p>
      <div slot="footer">
        <Button type="primary" size="large" @click="bztx">确定</Button>
      </div> 
    </Modal>

  </div>
</template>

<script>
  import ZssHeadermenu from '../components/headerMenu'
  export default {
      data () {
        return {
          spinShow:true,
          surplus:'',
          modal_loading:false,
          value4:'',
          userName:'',
          userCode:'',
          college_name:'',
          className: '',
          modalalert: false,
          zssczfs: false,
          zssfskc: false,
          zssfssz: false,
          zssbz: false,
          valueinput:"",
          beizhu: '',
          kf: {
            xsid: '',
            fs: '',
            content: '',
            chongzhinum:''
          },
          textarea: '',
          kfxx: [],
          columns4: [
            { 
              type:'index',
              title: '序号',
              width: 80,
              align: 'center',
              key: 'xh'
            },
            {
              title: '学号',
              key: 'userCode'
            },
            {
              title: '真实姓名',
              key: 'userName'
            },
            {
              title: '学院',
              key: 'college_name'
            },
            {
              title: '专业',
              key: 'systemName'
            },
            {
              title: '专业方向',
              key: 'majorName'
            },
            {
              title: '班级',
              key: 'className'
            },
            {
              title: '分数',
              key: 'integralSurplus'
            },
            {
              title: '备注',
              key: 'note'
            }
          ],
          xsxinxi: [],
          columnsopen: [
            {
              title: '时间',
              key: 'time'
            },
            {
              title: '积分记录',
              key: 'content'
            },
            {
              title: '扣分数',
              key: 'deductMark',
              align: 'center',
              width:80
            }
          ],
          dataopen: [],
          xsfy: {
            totalResult: 2967,//总数
            showCount: 15,//每页数据条数
            currentPage: 1,//当前页
            currentResult: 0,
            totalPage: 198 //总页数
          }
        }
    },
    components:{
      ZssHeadermenu
    },
    methods: {     

      // 学生列表数据开始
      dataLoad (keyword) {
        let that = this
        that.axios.get("/gleenSoft-base/credit/integral/students", {params: {
          //分页开始
          currentPage: that.xsfy.currentPage,
          //分页结束
          // 搜索参数开始
          keyword: that.value4
          // 搜索参数结束
        }}).then(
          (response) => {
            that.xsxinxi = response.data.result
            that.spinShow = false
            // 分页开始
            that.xsfy = response.data.page
            //分页结束
          }
        )
      },
      // 学生列表数据结束

      // 搜索开始
      sousuo () {
        let that = this
        that.dataLoad()
      },
      // 搜索结束

      //导出开始
      daochu(){
        let that = this
        window.open(`/gleenSoft-base/credit/integral/exportExcelStudents?keyword=${that.value4}`)
      },
      //导出结束

      

      //分页开始
      changePage (index) {
        let that = this
        that.xsfy.currentPage = index
        that.dataLoad()
      },
      //分页结束

      zssshow (row){
        let that = this
        that.studentId = row.id
        
        that.modalalert = true
        that.userName = row.userName
        that.userCode = row.userCode
        that.college_name = row.college_name
        that.className = row.className
        that.kf.xsid = row.id
        that.kf.chongzhinum = row.surplus

        //学生id获取开始
        window.zssxsid = row.id
        //学生id获取结束

        //get-id学生扣分纪录开始
        that.gerjl(row.id)
        //get-id学生扣分纪录结束
       
        that.surplus=row.integralSurplus
      },

      //记录导出开始
      daochujl(){
        let that = this
        window.open(`/gleenSoft-base/credit/integral/exportExcelStudent?studentId=${zssxsid}`)
      },
      //记录导出开始

      rowClassName (row,index) {
        if (index %2 != 1) {
          return 'demo-table-info-row'
        }
      },

      // 重置分数开始
      zssczfj (studentId,content) {
        this.modal_loading = true
        let that = this
        that.axios.post("/gleenSoft-base/credit/integral/set",{
          studentId: that.kf.xsid,
          content:"重置分数",
          type: 'INITIAL'
        }).then(
          (response) => {
            that.modal_loading = false
            that.zssczfs = false
            that.$Message.success('分数已重置')
            that.gerjl (window.zssid)
            that.dataLoad()
            that.surplus= response.data.surplus
          }
        )
      },
      // 重置分数结束

      //学生扣分选项开始
      kfgz (){
        let that = this
        that.axios.get("/gleenSoft-base/credit/rule/listNoPage",{params:{
          type:'MANUAL'
        }}).then(
          (response) => {
            that.kfxx = response.data.result
          }
        )
      },
      //学生扣分选项结束

      // 学生个人纪录开始
      gerjl (zssid){

        // 全局变量开始
        window.zssid = zssid
        // 全局变量结束

        let that = this
        that.axios.get("/gleenSoft-base/credit/integral/userIntegral",{params:{
          studentId: zssid
        }}).then(
          (response) => {
            that.dataopen = response.data.result
          }
        )
      },
      // 学生个人纪录开始

      //学生扣分保存开始
      kfxxchange (index) {
        let that = this
        that.kf.content = that.kfxx[index].content
        that.kf.fs = that.kfxx[index].value
      },
      gzqd (studentId, deductMark, content){
        let that = this
        that.axios.post("/gleenSoft-base/credit/integral/save",{
          studentId: that.kf.xsid,
          deductMark: that.kf.fs,
          content: that.kf.content,
          place:'',
          type:'MANUAL'
        }).then(
          (response) => {
            that.zssfskc = false
            that.$Message.success('扣分成功')
            that.gerjl (window.zssid)
            that.surplus = `${that.surplus - that.kf.fs}`
            that.dataLoad()
          }
        )
       
      },
      //学生扣分保存结束

      // 分数设置开始
      szfs (studentId,value){
        let that = this
        that.axios.post("/gleenSoft-base/credit/integral/set",{
          studentId:that.kf.xsid,
          value:that.valueinput,
          content:"分数设置",
          type:'SET'
        }).then(
          (response) => {
            that.zssfssz = false
            that.$Message.success('分数设置成功')
            that.surplus=that.valueinput
            that.gerjl (window.zssid)
            that.dataLoad()
          }
        )
      },
      // 分数设置结束

      // 备注填写开始
      bztx (){
        let that = this
         that.axios.post("/gleenSoft-base/credit/integral/setNote",{
          studentId:that.kf.xsid,
          note:that.beizhu,
          type:'SET'
        }).then(
          (response) => {
            that.zssbz = false
            that.$Message.success('填写成功')
            that.note = that.beizhu
            that.dataLoad()
          }
        )
      }
      // 备注填写结束
    },
    mounted () {
      this.dataLoad()
      this.kfgz()
    }
    
  }
</script>

<style scode>
h3{width: 150px;height: 150px;font-size: 20px;line-height: 150px;background:url(../../static/images/06ceffa373d49e64c5b11c601ff41a98.png) no-repeat;background-size:cover; }
.zss_p{padding: 8px;border-left: 5px solid #495060;display: inline;}
.zss_glxq p{margin: 10px 20px;text-align: left;}
.zss_guanlibox .ivu-table .demo-table-info-row td{
    background-color: #EEFAFF;
}
.zss_page{
  background: white;margin-top:10px;padding:10px;text-align: center;
}
</style>
